home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / Goodies / CallBack / SOURCE / HOSTENV.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-03  |  1.1 KB  |  45 lines

  1. /*
  2. *   Visual Basic Callback Server Source
  3. *
  4. *   (c) Copyright Microsoft Corp. 1995 All Rights Reserved
  5. */ 
  6.  
  7. #ifdef WIN32
  8. #ifndef UNICODE
  9. #include "hostenv.h"
  10. LPSYSSTR UNICODEtoANSI(BSTR bstrUNICODE)
  11. {
  12.     unsigned int iLen;
  13.     BSTR bstrANSI = NULL;
  14.     if (bstrUNICODE)
  15.         {
  16.         //iLen = SysStringLen(bstrUNICODE); //Doesn't work with system string.
  17.         if (0 == (iLen = lstrlenW(bstrUNICODE)))
  18.             {
  19.             unsigned short * pStr = bstrUNICODE;
  20.             while (*pStr++);
  21.             iLen = pStr - bstrUNICODE - 1;
  22.             }
  23.         if ( bstrANSI = SysAllocStringByteLen(NULL, iLen) )
  24.             {
  25.             WideCharToMultiByte(CP_ACP, 0, bstrUNICODE, -1, (LPSYSSTR)bstrANSI, iLen + 1, NULL, NULL); 
  26.             }
  27.         }
  28.     return (LPSYSSTR) bstrANSI;
  29. }
  30. BSTR ANSItoUNICODE(LPSYSSTR bstrANSI)
  31. {
  32.     unsigned int iLen;
  33.     BSTR bstrUNICODE = NULL;
  34.     if (bstrANSI)
  35.         {
  36.         //iLen = SysStringByteLen((LPOLESTR)bstrANSI);
  37.         iLen = lstrlenA(bstrANSI);
  38.         if ( bstrUNICODE = SysAllocStringLen(NULL, iLen) )
  39.             MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPSYSSTR)bstrANSI, -1, bstrUNICODE, iLen + 1); 
  40.         }
  41.     return bstrUNICODE; 
  42. }
  43. #endif
  44. #endif
  45.